Skip to content

feat(auth): implement refresh tokens#355

Open
GTR1701 wants to merge 6 commits into
mainfrom
feat/refresh-token
Open

feat(auth): implement refresh tokens#355
GTR1701 wants to merge 6 commits into
mainfrom
feat/refresh-token

Conversation

@GTR1701
Copy link
Copy Markdown
Member

@GTR1701 GTR1701 commented May 6, 2026

No description provided.

@GTR1701 GTR1701 requested a review from michalges as a code owner May 6, 2026 18:57
Copilot AI review requested due to automatic review settings May 6, 2026 18:57
@GTR1701 GTR1701 self-assigned this May 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Looks like you did not link an issue to this PR. If this PR completes a task, consider linking it.

@GTR1701 GTR1701 linked an issue May 6, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds client-side refresh-token handling so API calls can automatically refresh access tokens (or force a logout) based on token expiry state.

Changes:

  • Adds refresh-token response typing and new auth utilities for token status evaluation, refresh, and forced logout.
  • Updates the fetch execution path to refresh tokens before issuing requests when needed.
  • Introduces a client-side “deferred toast” helper and adds a session-expired toast message.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/lib/get-toast-messages.ts Adds a new auth.sessionExpired toast message string.
src/features/toaster/utils/defer-client-toast.ts New helper to persist a toast in a browser cookie outside React.
src/features/toaster/index.ts Re-exports deferClientToast.
src/features/backend/utils/execute-fetch.ts Adds pre-request token status check + refresh/force-logout logic (client only).
src/features/backend/types/responses.ts Adds RefreshTokenResponse typing for /auth/refresh.
src/features/authentication/utils/refresh-access-token.ts Adds a de-duplicated (singleton) refresh flow to prevent concurrent refresh piling.
src/features/authentication/utils/get-token-status.ts Adds token status evaluation (ok/expiring-soon/expired/both-expired).
src/features/authentication/utils/get-cookie-options.ts Aligns auth cookie expiry with refresh token expiry timestamp.
src/features/authentication/utils/force-logout.ts Adds a client-side forced logout helper that clears auth cookie, defers toast, redirects.
src/features/authentication/utils/do-refresh-token.ts Adds low-level refresh request + cookie persistence of refreshed access token.
src/features/authentication/types/internal.ts Adds TokenStatus type.
src/features/authentication/node.ts Re-exports new auth utilities for non-hook usage.
src/features/authentication/constants.ts Adds REFRESH_THRESHOLD_PERCENT constant for proactive refresh threshold.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/features/authentication/utils/do-refresh-token.ts Outdated
Comment thread src/features/backend/utils/execute-fetch.ts Outdated
Comment thread src/features/authentication/utils/get-token-status.ts Outdated
Comment thread src/features/authentication/utils/get-token-status.ts
Comment thread src/features/authentication/utils/force-logout.ts
Copy link
Copy Markdown
Member

@michalges michalges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git

Comment thread src/features/authentication/utils/do-refresh-token.ts Outdated
@michalges
Copy link
Copy Markdown
Member

można się jeszcze zastanowić czy gdy request zawiedzie z kodem 401 to czy nie próbować wtedy refreshować i ponowić request zamiast wylogowywać użytkownika. z tym żeby takie coś zaszło to musiałby być jakiś giga edge case z obecną logiką

Copilot AI review requested due to automatic review settings May 25, 2026 19:37
@GTR1701 GTR1701 force-pushed the feat/refresh-token branch from 1faef43 to dffc102 Compare May 25, 2026 19:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Comment on lines +3 to +7
export * from "./utils/force-logout";
export * from "./utils/get-auth-state.node";
export * from "./utils/get-cookie-options";
export * from "./utils/get-token-status";
export * from "./utils/refresh-access-token";
Comment thread src/features/backend/utils/execute-fetch.ts
Comment thread src/features/authentication/utils/force-logout.ts
Comment on lines +7 to +12
/**
* Saves a toast message in a browser cookie to be displayed on the next page render.
* For use **outside** of React components, where the {@link useSavedToast} hook cannot be used.
*/
export const deferClientToast = (toast: SavedToast): void => {
Cookies.set(SAVED_TOAST_COOKIE_NAME, ...getSavedToastCookieOptions(toast));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dodać odświeżanie refresh tokenów

3 participants